package top.yaofengqiao.springcloudsimple.system.biz.infrastructure.repository;

import org.springframework.stereotype.Repository;
import top.yaofengqiao.springcloudsimple.system.biz.domain.log.repository.IOperatorLogRepository;
import top.yaofengqiao.springcloudsimple.system.biz.infrastructure.dao.OperatorLogMapper;
import top.yaofengqiao.springcloudsimple.system.biz.infrastructure.po.OperatorLogPO;
import top.yaofengqiao.springcloudsimple.web.starter.util.OperatorLog;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @author yfq
 * @date 16:31
 * @description
 */
@Repository
public class OperatorLogRepository implements IOperatorLogRepository {
    @Resource
    private OperatorLogMapper operatorLogMapper;

    @Override
    public boolean save(OperatorLog operatorLog) {
        OperatorLogPO operatorLogPO = new OperatorLogPO();
        operatorLogPO.setTraceId(operatorLog.getTraceId());
        operatorLogPO.setUserId(operatorLog.getUserId());
        operatorLogPO.setRequestMethod(operatorLog.getRequestMethod());
        operatorLogPO.setUri(operatorLog.getUri());
        operatorLogPO.setUserIp(operatorLog.getIp());
        operatorLogPO.setCreateTime(LocalDateTime.now());
        operatorLogPO.setUpdateTime(LocalDateTime.now());

        return operatorLogMapper.insert(operatorLogPO) == 1;
    }

}
